import 'package:flutter/material.dart';
import 'package:flutter_deer/account/models/account_summary_entity.dart';
import 'package:flutter_deer/index/models/football_ratio_entity.dart';
import 'package:flutter_deer/util/other_utils.dart';
import 'package:flutter_deer/widgets/state_layout.dart';

class GameGroupDetailPageProvider extends ChangeNotifier {

  FootballRatioGroupEntity? _groupEntity;
  String? _bettingId;
  bool? _loading;
  bool? _giveScoreChecked = false;
  double? _residueGiveScore = 0.0;
  FootballRatioGroupEntity? get groupEntity => _groupEntity;
  bool? get loading => _loading;
  bool? get giveScoreChecked => _giveScoreChecked;
  double? get residueGiveScore => _residueGiveScore;
  String? get bettingId => _bettingId;
  StateType? _accountSummaryStateType = StateType.loading;
  StateType? get accountSummaryStateType => _accountSummaryStateType;
  AccountSummaryEntity? _accountSummaryData;
  AccountSummaryEntity? get accountSummaryData => _accountSummaryData;
  double? get orderAmount => _orderAmountStr!=''?double.tryParse(_orderAmountStr.nullSafe):0;
  double? get willPrizeAmount => _groupEntity!.groupRatio!*orderAmount!;
  String? _orderAmountStr = '';
  String? get orderAmountStr => _orderAmountStr;

  void setGroupEntity(FootballRatioGroupEntity? group){
    _groupEntity = group;
    _loading = false;
    notifyListeners();
  }

  void setLoading(bool? val) {
    _loading = val;
    notifyListeners();
  }

  void setGiveScoreChecked(bool? val) {
    _giveScoreChecked = val;
    notifyListeners();
  }

  void setResidueGiveScore(double? val) {
    _residueGiveScore = val;
    notifyListeners();
  }

  void setBettingResult(String? val) {
    _bettingId = val;
    notifyListeners();
  }

  void setAccountSummaryLoading() {
    this._accountSummaryStateType = StateType.loading;
    notifyListeners();
  }

  void setAccountSummary(AccountSummaryEntity? entity) {
    this._accountSummaryData = entity;
    this._accountSummaryStateType = StateType.empty;
    notifyListeners();
  }

  Future<dynamic> appendOrderAmountStr(String value) async {
    _orderAmountStr = _orderAmountStr.nullSafe + value;
    notifyListeners();
  }

  Future<dynamic> deleteOrderAmountStrByLast() async {
    if(_orderAmountStr.nullSafe.length>0) {
      _orderAmountStr = _orderAmountStr.nullSafe
          .substring(0, _orderAmountStr.nullSafe.length - 1)
          .nullSafe;
    }else{
      _orderAmountStr = '';
    }
    notifyListeners();
  }

  Future<dynamic> resetOrderAmmountStr() async {
    _orderAmountStr = '';
    notifyListeners();
  }
}